package com.xxl.job.admin.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import com.xxl.job.admin.core.model.XinApi;
import com.xxl.job.admin.dao.XinApiDao;

@Repository
public class XinApiDaoImpl implements XinApiDao {
	
	@Resource
	public SqlSessionTemplate sqlSessionTemplate;
	
	@Override
	public List<XinApi> findAll(int start, int num) {
		Map<String, Object>map = new HashMap<>();
		map.put("start", start);
		map.put("num", num);
		return sqlSessionTemplate.selectList("XinApiMapper.findAll", map);
	}
	
	public int countPages(int num) {
		//return 10;
		return sqlSessionTemplate.selectOne("XinApiMapper.count");
	}

	@Override
	public boolean save(XinApi xinapi) {
		if(sqlSessionTemplate.insert("XinApiMapper.save", xinapi)>0)
		{	
			return true;
		} else {
			return false;
		}
	}

	@Override
	public boolean update(XinApi xinapi) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean remove(int id) {
		if(sqlSessionTemplate.delete("XinApiMapper.delete", id)>0){
			return true;
		} else {
			return false;
		}
	}

	@Override
	public XinApi load(int id) {
		// TODO Auto-generated method stub
		return null;
	}

}
